//
//  ModelParser.m
//  NewsReader
//
//  Created by blacksun on 11-2-17.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "ModelParser.h"


@implementation ModelParser


+(NSMutableArray *) parseFeeds:(NSDictionary *)response{
	NSMutableArray *formatedFeeds = [[[NSMutableArray alloc] init] autorelease];
	if (!response) {
		return formatedFeeds;
	}
	NSArray *feeds = [response objectForKey:@"feeds"];
	for (NSDictionary *feed in feeds) {
		Feed *temp = [[Feed alloc] init];
		temp.feedId = [(NSString *)[feed objectForKey:@"index"] integerValue];
		temp.sectionId = [feed objectForKey:@"sectionId"];
		temp.description = [feed objectForKey:@"summary"];
		temp.author = [feed objectForKey:@"source"];
		temp.title = [feed objectForKey:@"title"];
		temp.link = [feed objectForKey:@"link"];
		temp.pubDate = [feed objectForKey:@"pubDate"];
		temp.complete = [feed objectForKey:@"complete"];
		NSArray *newDetails = [feed objectForKey:@"detail"];
		NSMutableArray *details = [[NSMutableArray alloc] init];
		for (NSDictionary *detail in newDetails) {
			Content *content = [[Content alloc] init];
			content.feedId = temp.feedId;
			content.type = [detail objectForKey:@"type"];
			content.width = [(NSString *)[detail objectForKey:@"width"] integerValue];
			content.heigth = [(NSString *)[detail objectForKey:@"height"] integerValue];
			content.content = [detail objectForKey:@"content"];
			content.src = [detail objectForKey:@"src"];
			
			[details addObject:content];
			[content release];
		}
		temp.details = details;
		[details release];
		
		temp.thumb = [feed objectForKey:@"thumb"];
		temp.createDate = [feed objectForKey:@"pubDate"];
		[formatedFeeds addObject:temp];
		[temp release];
	}
	return formatedFeeds;
}

@end
